package cn.neusoft.luofa603.yuejian_29.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.media.MediaMetadataRetriever;
import android.media.ThumbnailUtils;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.HashMap;
import java.util.List;
import cn.neusoft.luofa603.yuejian_29.R;
import cn.neusoft.luofa603.yuejian_29.activity.VideoActivity;
import cn.neusoft.luofa603.yuejian_29.bean.Video;

/**
 * Created by Administrator on 2017/10/31.
 */

public class ClubVideoAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List mDataList;
    private String cvpath,path;
    private LayoutInflater mLayoutInflater;


    public ClubVideoAdapter(Context mContext, List mDataList){

        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
         ImageView video_pic;
         TextView video_name;

        public ViewHolder(View itemView) {
            super(itemView);
            video_pic=(ImageView)itemView.findViewById(R.id.img_video);
            video_name=(TextView)itemView.findViewById(R.id.videoname);

        }

    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.item_video,parent,false);
        return new ClubVideoAdapter.ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Video entity = (Video)mDataList.get(position);
        if (null==entity){
            return;
        }

        ClubVideoAdapter.ViewHolder viewHolder=(ClubVideoAdapter.ViewHolder) holder;
        cvpath=entity.getCvpath();
        path="http://115.159.93.244/new18yuejian/Public/upload/"+cvpath;
        viewHolder.video_name.setText(entity.getCvname());

//        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
//        retriever.setDataSource(path,new HashMap<String, String>());
//        Bitmap thumb = retriever.getFrameAtTime();
//        viewHolder.video_pic.setImageBitmap(thumb);

        viewHolder.video_pic.setImageResource(R.drawable.img1);

//        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
//        retriever.setDataSource(path,new HashMap<String, String>());
//        viewHolder.video_pic.setImageBitmap(retriever.getFrameAtTime());

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
//            cvname=mDataList.get(position).getCvname();
//            cvpath=mDataList.get(position).getCvpath();
                Intent intent = new Intent();
                intent.setClass(mContext, VideoActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("video_path", cvpath);
                intent.putExtras(bundle);
                mContext.startActivity(intent);
            }
        });


    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }


}
